{extend name="index_layout"/}
{block name="main"}
<form class="layui-form" method="post">


    <div class="layui-form-item">
        <label class="layui-form-label">会员分组</label>
        <div class="layui-input-block">
            {:Form::radios('row[type_name]',[1=>'A类会员', 2=>'B类会员',3=>'C类会员',4=>'D类会员'])}
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员名称</label>
        <div class="layui-input-block">
            <input id="c-name" lay-verify="required" class=" layui-input" name="row[name]" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">会员类型</label>
        <div class="layui-input-block">
            <select name="row[type]" id="">
                <option value="1">月</option>
                <option value="2">季</option>
                <option value="3">年</option>
                <option value="4">终身</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">时间数量</label>
        <div class="layui-input-block">
            <input id="c-nums" lay-verify="required" class=" layui-input" name="row[nums]" type="number">
        </div>
        <div class="layui-form-mid no-float layui-word-aux">数量，为会员类型的数量。几个月，几个季度，几年</div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">折扣</label>
        <div class="layui-input-block">
            <input id="c-discount" lay-verify="required" class="layui-input" name="row[discount]" type="text" placeholder="请输入折扣，范围在1-10之间" pattern="^(0(\.\d{1,2})?|1(\.0{1,2})?)$" title="请输入0到1之间的数字，最多保留两位小数">
        </div>
        <div class="layui-form-mid no-float layui-word-aux">折扣，范围在1-10之间</div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标签</label>
        <div class="layui-input-block">
            <input id="c-tag" class="form-tags layui-input" name="row[tag]" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">划线价格</label>
        <div class="layui-input-block">
            <input id="c-original_price" lay-verify="required" class=" layui-input" step="0.01"
                   name="row[original_price]" type="number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-block">
            <input id="c-price" lay-verify="required" class=" layui-input" step="0.01" name="row[price]" type="number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">特殊省份价格</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal" id="add-price">添加价格</button>
            <table class="layui-table" id="price-table">
                <thead>
                <tr>
                    <th>省份</th>
                    <th>价格</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">套餐</label>
        <div class="layui-input-block">
            <input id="c-account_cate_id" data-multiple="true"	 lay-verify="" data-source="admin/company_package/index"
                   class="selectpage layui-input" name="row[package_id]" type="text" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="row[status]" value="1" title="显示" checked>
            <input type="radio" name="row[status]" value="0" title="隐藏">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input id="c-sort" lay-verify="required" class=" layui-input" name="row[sort]" type="number" value="50">
        </div>
    </div>
    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    $(document).ready(function(){
        // 添加价格按钮点击事件
        $("#add-price").click(function(){
            var newRow = '<tr>' +
                '<td><select class="province-dropdown" multiple name="province[]"></select></td>' +
                '<td><input type="text" class="layui-input price-input" name="price[]"></td>' +
                '<td><button type="button" class="layui-btn layui-btn-danger delete-row">删除</button></td>' +
                '</tr>';
            // 添加新行
            $("#price-table tbody").append(newRow);

            // 请求省份数据
            $.ajax({
                url: '/admin/area/getList',
                method: 'GET',
                success: function(data) {
                    // 将省份数据添加到多选下拉框中
                    var selectOptions = '';
                    data.forEach(function(province){
                        selectOptions += '<option value="' + province.shortname + '">' + province.shortname + '</option>';
                    });
                    // 将选项添加到最新添加的多选下拉框中
                    $('.province-dropdown:last').html(selectOptions);
                    // 使用 layui 的 select 组件渲染多选下拉框
                    layui.use('form', function(){
                        var form = layui.form;
                        form.render('select');
                    });
                },
                error: function(xhr, status, error) {
                    console.error('Failed to fetch province data:', error);
                }
            });
        });

        // 删除按钮点击事件
        $(document).on('click', '.delete-row', function(){
            $(this).closest('tr').remove();
        });
    });</script>

<script type="text/javascript">
    layui.use('yznForm', function () {
        var yznForm = layui.yznForm;
        yznForm.bindevent($("form.layui-form"));
    });
</script>
{/block}